package com.sam.designpattern.command;

/**
 * @Author: Sam
 * @Date: 2022-08-26 17:01
 * @Description: 命令模式客户端
 */
public class Client {
    public static void main(String[] args) {
        OperationAPi operation = new Operation();
        operation.setResult(10);
        System.out.println("初始值为：10");
        AddCommand addCmd = new AddCommand(operation, 5);
        SubstractCommand substractCmd = new SubstractCommand(operation, 3);

        Calculator calculator = new Calculator();
        calculator.setAddCmd(addCmd);
        calculator.setSubstractCmd(substractCmd);

        calculator.addPressed();
        System.out.println("加法运算后的结果为：" + operation.getResult());
        calculator.substractPressed();
        System.out.println("减法运算后的结果为：" + operation.getResult());

        calculator.undoPressed();
        System.out.println("一次撤销后的结果为：" + operation.getResult());
        calculator.undoPressed();
        System.out.println("两次撤销后的结果为：" + operation.getResult());
        calculator.redoPressed();
        System.out.println("一次恢复后的结果为：" + operation.getResult());
        calculator.redoPressed();
        System.out.println("两次恢复后的结果为：" + operation.getResult());
        calculator.redoPressed();
        System.out.println("三次恢复后的结果为：" + operation.getResult());
    }
}
